package com.stsdai.item.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.stsdai.manager.pojo.Content;
import com.stsdai.manager.pojo.Item;
import com.stsdai.manager.pojo.ItemDesc;
import com.stsdai.manager.service.ContentService;
import com.stsdai.manager.service.ItemDescService;
import com.stsdai.manager.service.ItemService;

@Controller
@RequestMapping("item")
public class ItemController {

	@Autowired
	private ItemService itemService;
	
	@Autowired
	private ItemDescService itemDescService;
	
	@Autowired
	private ContentService contentService;
	
	//http://item.stsdai.com/item/1474391929.html
	
	/**
	 * 实现显示商品详细页
	 * @param model
	 * @param itemId
	 * @return
	 */
	@RequestMapping("{itemId}")
	public String queryItemById(Model model,@PathVariable Long itemId){
		//使用商品服务，根据商品id查询商品基础数据
		Item item = this.itemService.queryById(itemId);
		
		/*item.setPrice(item.getPrice()*100);*/
		//使用商品服务，根据商品id查询商品描述数据
		ItemDesc itemDesc = this.itemDescService.queryById(itemId);
		//把商品基础数据放到Model，传递给前台页面
		model.addAttribute("item",item);
		//把商品描述数据放到Model，传递给前台页面
		model.addAttribute("itemDesc", itemDesc);
		
		//查询详情页广告
		List<Content> xiangQing = this.contentService.queryLeftItemXiangQing();
		model.addAttribute("xiangQing", xiangQing);
		
		return "item";
	}
	
}
